package com.zhbr.interceptor;


import androidx.annotation.NonNull;

import com.zhbr.common.StringUtils;
import com.zhbr.ContextApplication;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * @author yangming on 2018/7/19
 * OKHttpClient请求头
 */
public class HeaderInterceptor implements Interceptor {

    @Override
    public Response intercept(@NonNull Chain chain) throws IOException {

        final Request.Builder builder = chain.request().newBuilder();
         //TODO

        String accessToken = ContextApplication.getInstance().readFromSP("user_info","token");
        if (!StringUtils.isEmpty(accessToken)) {
            builder.addHeader("token", accessToken);
        }
//        builder.addHeader("token","eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIxMjU4MCIsImV4cCI6MTYwOTIyNzEwOCwiaWF0IjoxNjA5MTQwNzA4fQ.RHUbZzMcfAqcxCHrbM0p-bkrDw7sfWzoBpRvLp_88eQ");

        return chain.proceed(builder.build());
    }
}
